package labox.innovation.gameserver.network.clientpackets;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;
import labox.innovation.gameserver.network.serverpackets.ActionFailed;

/**
 * 登出请求
 *
 * @version $Revision: 1.9.4.3 $ $Date: 2005/03/27 15:29:30 $
 */
public final class Logout extends L2GameClientPacket {

	private static final String _C__09_LOGOUT = "[C] 09 Logout";

	private static final Logger _log = LoggerFactory.getLogger(Logout.class.getName());
	
	private boolean _getCharList;

	@Override
	protected void readImpl() {
		_getCharList=readByte()==0?false:true;
	}

	@Override
	protected void runImpl() {
		// Dont allow leaving if player is fighting

		FuzePcInstance player = getClient().getActiveChar();
		
		if(player==null)
			return;

		if (player.atEvent) {
			player.sendMessage("A superior power doesn't allow you to leave the event");
			player.sendPacket(ActionFailed.STATIC_PACKET);
			return;
		}

		player.logout(_getCharList);
	}

	/* (non-Javadoc)
	 * @see labox.innovation.gameserver.clientpackets.ClientBasePacket#getType()
	 */
	@Override
	public String getType() {
		return _C__09_LOGOUT;
	}
}